import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'
import Articlelist from '../views/Nest/Articlelist.vue'
import Issuelist from '../views/Nest/Issuelist.vue'
// import Compile from '../views/Compile'

// 购物车
// import cat from '../views/cat'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: 'articlelist', //嵌套路由不需要根目录
        name: 'Articlelist',
        component: Articlelist,
      },
      {
        path: 'issuelist', //嵌套路由不需要根目录
        name: 'Issuelist',
        component: Issuelist,
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  // {
  //   path: '/register',
  //   name: 'Register',
  //   component: Register
  // },

]
const router = new VueRouter({
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    if (localStorage.getItem('token')) {
      return next()
    } else {
      return router.push('/login').catch(err => {

      })
    }
  }
  return next()
})



export default router
